package com.design.pattern.observer;

import java.util.Observable;
import java.util.Observer;

public class ForecastDisplay2 implements Observer ,DisplayElement {

    private Observable observable;
    private float temp;
    private float humidity;
    private float pressure;

    public ForecastDisplay2(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    public void display() {
        System.out.println("ForecastDisplay2 当前温度：" + temp + "F; 湿度为：" + humidity + "%; 气压为:" + pressure);
    }

    public void update(Observable obs, Object arg) {
        if(obs instanceof WeatherData2){
            WeatherData2 weatherData2 = (WeatherData2) obs;
            this.temp = weatherData2.getTemp();
            this.humidity = weatherData2.getHumidity();
            this.pressure = weatherData2.getPressure();
            display();
        }
    }
}